#include "stdafx.h"

#include "Business/PriceChangeChecker.h"
#include "Business/PendingMarket.h"
#include "Utils/TimeUtils.h"
#include "Utils/Logger.h"
#include "Utils/Formatter.h"

PriceChangeChecker::PriceChangeChecker(int minPriceUnit,int maxTime,int marketCount,int changeQuantity) 
:m_marketCount(marketCount),m_maxTime(maxTime),m_changePriceBalance(minPriceUnit * changeQuantity),
m_buyPrices(marketCount),m_sellPrices(marketCount)
{
}

bool PriceChangeChecker::IsBuyBigChange(int price)
{
	m_buyPrices.push_back(PriceAndTime(price,MyGetTickCount()));
	LightLogger::Info(FT("Buy Major Market [%d]",price));
	PriceAndTime const& last = m_buyPrices.back();
	for (PriceAndTimes::const_reverse_iterator iter = m_buyPrices.rbegin();
		iter != m_buyPrices.rend();
		++iter)
	{
		if (last.price - iter->price >= m_changePriceBalance &&
			last.time - iter->time <= m_maxTime)
		{
			return true;
		}
	}
	return false;
}

bool PriceChangeChecker::IsSellBigChange(int price)
{
	m_sellPrices.push_back(PriceAndTime(price,MyGetTickCount()));
	LightLogger::Info(FT("Sell Major Market [%d]",price));
	PriceAndTime const& last = m_sellPrices.back();
	for (PriceAndTimes::const_reverse_iterator iter = m_sellPrices.rbegin();
		iter != m_sellPrices.rend();
		++iter)
	{
		if (last.price - iter->price <= -m_changePriceBalance &&
			last.time - iter->time <= m_maxTime)
		{
			return true;
		}
	}
	return false;
}